import Vue from "vue";
import Router from "vue-router";


Vue.use(Router);
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);
//引入登录组件
import Login from './views/login.vue'

// 引入主页
import Home from "./components/home/Home.vue";
//引入welcome组件
import Welcome from './components/home/welcome.vue';
// 引入userList组件
import UserList from './components/home/UserList.vue'
// 引入rightsList组件
import RightList from './components/home/RightList.vue'
// //引入roles组件
import Roles from './components/home/Roles.vue'
// 引入Categories组件
import Categories from './components/home/Categories.vue'
// 引入params组件
import Params from './components/home/Params.vue'
// 引入order组件
import Orders from './components/home/Orders.vue'
// 引入goods组件
import Goods from './components/home/Goods.vue'
// 引入Add组件
import Add from './components/home/Add.vue'
// 引入reports组件
import Reports from './components/home/reports.vue'
const router = new Router({
  mode: "history",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      redirect: "/home"
    },
    {
      path: "/login",
      name: "login",
      component: Login
    },
    {
      path: "/home",
      redirect: "/welcome",
      component: Home,
      name: "home",
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/users', component: UserList },
        { path: '/rights', component: RightList },
        { path: '/roles', component: Roles },
        { path: '/categories', component: Categories },
        { path: '/params', component: Params },
        { path: '/orders', component: Orders },
        {
          path: '/goods',
          component: Goods,
          
        },
        { path: '/goods/add', component: Add },
        { path: '/reports', component: Reports }
      ]
    },
  ]
});
//路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path == "/login") return next();
  const token = window.sessionStorage.getItem("token");
  console.log(token)
  if (!token) return next("/login");

  next();
});
//暴露router
export default router;
